<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>疫苗基本信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
		});
		$(document).on("change","#vaccineId",function(){
			var nameAll = $(this).val();
			$("#vaccNameAll").val(nameAll.substring(nameAll.indexOf('-')+1));
		});
		$("#vaccineId").change(function(){ 
			$(this).next().text("");
			}); 
		$("#spec").change(function(){ 
			$(this).next().text("");
			});
		$("#companyCode").change(function(){ 
			$(this).next().text(""); 
			}); 
			$("#type").change(function(){  
				$(this).next().text(""); 
			});
			$(".input-text").blur(function(){  
				if($(this).val() != ""){
					$("#dose").next().text("");	
			} 
			});
		$("#containerTypeNam").change(function(){ 
			$(this).next().text("");
			});
		$("#doseType").change(function(){ 
			$(this).next().text(""); 
			});
		$("#islive").change(function(){  
			$(this).next().text("");
			});
		$("#dose").change(function(){  
			$(this).next().text("");
			});
		$("#customBillNo").blur(function(){  
			if($(this).val() != ""){
			    $(this).next().text("");	
			}
			}); 
		initVaccName();
		initCompanyName();
		initDose();
		});
		function initVaccName(){
			debugger;
			var select='<option value="">--请选择--</option>';
			var url = "${ctx}/vaccinate/bsVaccine/getVaccineName";
			$.ajax({
				url : url,	
				success : function(data){
					data=$.parseJSON(data);
					var str="${bsVaccineInfo.vaccineId}";
					for(var i=0;i<data.length;i++){
						if(data[i].id==str){
							select+="<option value='"+data[i].id+"-"+data[i].nameAll+"' selected>"+data[i].name+"</option>";
						}else{
						    select+="<option value='"+data[i].id+"-"+data[i].nameAll+"'>"+data[i].name+"</option>";
						}
					};
					$("#vaccineId").append(select).select2();
				}
			});
		}
		 function initCompanyName(){
				var select='<option value="">--请选择--</option>';
				var url = "${ctx}/company/bsCompany/getCompany";
				var comcode = "${bsVaccineInfo.companyCode}";
				$.ajax({
					url : url,	
					success : function(data){
						data=$.parseJSON(data); 
						for(var i=0;i<data.length;i++){
							select+="<option value='"+data[i].code+"'>"+data[i].name+"</option>";
						};
						$("#companyCode").append(select).select2();
						$("#companyCode").val(comcode).select2();
					}
				});
			
		}
		 function initDose(){
				var select='<option value="">--请选择--</option>';
				var url = "${ctx}/vaccinate/bsVaccineInfo/getByDose";
				$.ajax({
					url : url,	
					success : function(data){
						data=$.parseJSON(data);
						for(var i=0;i<data.length;i++){
							select+="<option value='"+data[i].dose+"'>"+data[i].dose+"</option>";
						};
						$("#dose").append(select).select2();
					}
				});
			}
		//重定向页面跳转
		function closeIframe(){
			var index = parent.layer.getFrameIndex(window.name);
			if(index){
				parent.layer.close(index);
			}else{
				window.location.href = "${ctx}/vaccinate/bsVaccineInfo/findAll";
			}
		}
		
		function save(){
			if($("#vaccineId").val() == ""){
				$("#vaccineId").next().text("*必填信息");
			}if($("#companyCode").val() == ""){
				$("#companyCode").next().text("*必填信息");
			}if($("#type").val() == ""){
				$("#type").next().text("*必填信息");
			}if($("#containerTypeNam").val() == ""){
				$("#containerTypeNam").next().text("*必填信息");
			}if($("#doseType").val() == ""){
				$("#doseType").next().text("*必填信息");
			}if($(".input-text").val() == ""){
				$("#dose").next().text("*必填信息");
			}if($("#islive").val() == ""){
				$("#islive").next().text("*必填信息");
			}if($("#customBillNo").val() == ""){
				$("#customBillNo").next().text("*必填信息");
			}if($("#spec").val() == ""){
				$("#spec").next().text("*必填信息");
			}else{
				layer.confirm('确定保存？', {
					btn : [ '保存', '取消' ]
				}, function() {
					var url = "${ctx}/vaccinate/bsVaccineInfo/getByBillNo";
					$.ajax({
						url : url,	
						data:{
							"vaccineId" : $("#vaccineId").val().substring(0,$("#vaccineId").val().indexOf("-")),
						    "companyCode" : $("#companyCode").val(),
						    "containerTypeNam" : $("#containerTypeNam").val(),
						    "doseType" : $("#doseType").val(),
						    "dose" : $(".input-text").val(),
						    "spec" : $("#spec").val(),
						    "customBillNo":$("#customBillNo").val()
						},
						success : function(data){
		                       if(data == 'true'){
			                       	if($("#id").val() != ''){
			                       		check();
			                       	}else{
			                       		layer.msg("存在重复的疫苗基本信息，请慎重选择!");
		                       	    }
		                       }else{
		                       	  check();
		                       }
						},
					 });
				});
			}
		}
		function change(){
			$(".input-text").val($("#dose").val());
		}
		function check(){
			$.ajax({
				url : "${ctx}/vaccinate/bsVaccineInfo/saveBatchno",
				data :{
                       "id" : "${bsVaccineInfo.id}",
                       "vaccineId" : $("#vaccineId").val().substring(0,$("#vaccineId").val().indexOf("-")),
					   "companyCode" : $("#companyCode").val(),
					   "type":$("#type").val(),
					   "containerTypeNam" : $("#containerTypeNam").val(),
					   "doseType" : $("#doseType").val(),
					   "dose" : $(".input-text").val(),
					   "islive" : $("#islive").val(),
					   "spec" : $("#spec").val(),
					   "customBillNo":$("#customBillNo").val(),
					   "largePackage":$("#largePackage").val(),
					   "code" : $("#code").val(),
					   "vaccNameAll" : $("#vaccNameAll").val()
				},
				success: function(data){
					if(data){
						layer.msg("保存成功!");
							setTimeout('closeIframe()',2000);
					}
				}
			});
		}
	</script>
	
	<style type="text/css">
/* 		body{ */
/* 			padding:20px; */
/* 		} */
		.minWidth {
			min-width: 500px;
		}
		
		@media ( min-width : 789px) and (max-width: 1098px) {
			.secondChild {
				margin-left: 0
			}
		}
		[class*="span"] {
			margin-left: 0px;
		}
		.box{
			position: relative;
			height: 26px;
		}
		.input-text{
			width: 237px;
			height: 26px;
			/* border: none; */
			outline-color: #ccc;
			/* box-sizing: border-box; */
			padding: 0px;
			position: absolute;
			/* left: 2px;
			top: 2px; */
			z-index: 1;
		}
 		.selected{
 			width: 212px; 
 			height: 28px;
 		    border: 1px solid #e6e0e0; 
			outline-color: #ccc;
 			padding: 0px;
 			border-radius: 6px;
			position: absolute;
			/* left: 0; 
  		    top: 0; */ 
 			z-index: 0;
			/* background: #e6e0e0; */ 
		}
	</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/vaccinate/bsVaccineInfo/findAll">疫苗基本信息列表</a></li>
		<shiro:hasPermission name="vaccineinfo:bsVaccineInfo:edit">
			<li class="active">
			<a href="${ctx}/vaccinate/bsVaccineInfo/form1?id=${bsVaccineInfo.id}">疫苗基本信息<shiro:hasPermission name="vaccineinfo:bsVaccineInfo:edit">${not empty bsVaccineInfo.id?'修改':'添加'}</shiro:hasPermission></a></li>
		</shiro:hasPermission>
	</ul>
	<form:form id="inputForm"  modelAttribute="bsVaccineInfo" action="${ctx}/vaccinate/bsVaccineInfo/saveBatchno" method="post" class="form-horizontal">
	   <input type="hidden" id="id" name ="id" value="${bsVaccineInfo.id}"/>
	   <sys:message content="${message}"/>
       <div class="control-group">
			<label class="control-label">疫苗名称：</label>
			<div class="controls">
			<form:select path="vaccineId" class="input-xlarge">
			</form:select>
			<span class="help-inline" style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">疫苗全称：</label>
			<div class="controls">
				<form:input path="vaccNameAll" htmlEscape="false" maxlength="100" class="input-xlarge" readonly="true"/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">生产企业：</label>
			<div class="controls">
			<form:select path="companyCode" class="input-xlarge">
			</form:select>
			<span class="help-inline" style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">疫苗类型：</label>
			<div class="controls">
				<form:select path="type" class="input-xlarge">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline" style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">容器类型：</label>
			<div class="controls">
				<form:select path="containerTypeNam" class="input-xlarge ">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('bs_vaccineInfo_containerType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline" style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">剂型：</label>
			<div class="controls">
				<form:select path="doseType" class="input-xlarge ">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('bs_vaccineInfo_doseType')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"  style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">剂量：</label>
			<div class="controls" id="app" class="box">
				<input class="input-text" type="text" value="${bsVaccineInfo.dose}"/>
				     <form:select path="dose" class="input-xlarge" onchange="change()">
				     </form:select>
				     <span class="help-inline" style="color:red"></span>
				     <p></p>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">是否为活苗：</label>
			<div class="controls">
				<form:select path="islive" class="input-xlarge ">
					<form:option value="" label="--请选择--"/>
					<form:options items="${fns:getDictList('yes_no')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline" style="color:red"></span>
		    </div>
		</div>
		<div class="control-group">
			<label class="control-label">规格：</label>
			<div class="controls">
				<form:input path="spec" htmlEscape="false" maxlength="100" class="input-xlarge digits"/>
				<span class="help-inline" style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">批准文号：</label>
			<div class="controls">
				<form:input path="customBillNo" htmlEscape="false" maxlength="100" class="input-xlarge "/>
				<span class="help-inline"  style="color:red"></span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">进口通关单编号：</label>
			<div class="controls">
				<form:input path="code" htmlEscape="false" maxlength="100" class="input-xlarge "/>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><font color="red">* </font>大包装(支(粒)/箱)：</label>
			<div class="controls">
				<form:input path="largePackage" htmlEscape="false" maxlength="100" class="input-xlarge digits required"/>
			</div>
		</div>
		<div class="form-actions">
			<input id="btnSubmit" class="btn btn-primary" type="button"   value="保 存" onclick="save()"/>&nbsp;&nbsp;
			<input id="btnClose" class="btn btn-primary" type="button" onclick="history.go(-1)" value="关闭"/>
		</div>
</form:form>
</body>
</html>